import json
from PyQt5.QtWidgets import QListWidget, QListWidgetItem, QSizePolicy
from PyQt5.QtCore import QRect, Qt, QSize


class CList(QListWidget):
    def __init__(self, parent=None):
        super(CList, self).__init__(parent)
        self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored))
        
            
    def updateUi(self, data=[]):
        for itemTitle in data:
            # item = QListWidgetItem(json.dumps(itemTitle))
            if isinstance(itemTitle, dict) or isinstance(itemTitle, list):
                item = QListWidgetItem(json.dumps(itemTitle))
            else:
                item = QListWidgetItem(itemTitle)
            self.addItem(item)
            
    def addValue(self, value, data=None):
        item = QListWidgetItem(value)
        if data:
            item.setData(Qt.UserRole, data)
        self.addItem(item)
    
    def updateValue(self, item, value, data=None):
        item.setText(value) 
        if data:
            item.setData(Qt.UserRole, data)
            
    def getItemData(self, item):
        return item.data(Qt.UserRole)

        
        






    
 


